package org.example.pglog.controller;

import org.example.pglog.mapper.UserMapper;
import org.example.pglog.pojo.BeanDiff;
import org.example.pglog.pojo.User;
import org.example.pglog.service.LogService;
import org.example.pglog.util.BeanCompareUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: 船长
 * @create: 2024-09-01 18:22
 **/

@RestController
public class TestController {

    @Autowired
    private UserMapper userMapper;
    @Autowired
    private LogService logService;

    @PostMapping("/save")
    public String save(@RequestBody User user){
        int i = userMapper.insert(user);
        return i > 0 ? "success" : "fail";
    }

    @PostMapping("/update")
    public String update(@RequestBody User user){
        User user1 = userMapper.selectById(user.getId());
        logService.db(user1, user,new String[]{"name","age","hobby"});
        int i = userMapper.updateById(user);
        return i > 0 ? "success" : "fail";
    }

}
